#ifndef SIGN_SCAN_STATE_H
#define SIGN_SCAN_STATE_H

#include <QDialog>
#include <QTimer>
#include <QMutex>

#include "SearchController/SearchType.h"

class SearchController;
class IConfig;

namespace Ui {
class sign_scan_state;
}

struct Statistics
{
    int total;
    int infected;
    int errors;
    bool canceled;

    Statistics() :
        total(0), infected(0), errors(0), canceled(false)
    {
    }
};

class ProgressDialog : public QDialog
{
    Q_OBJECT
    
public:
    /**
     * @param bFileType
     *      true - path is a file
     *      false - path is a folder
     */
    explicit ProgressDialog(QWidget *parent, const QString & path, bool bFileType, IConfig *config);
    explicit ProgressDialog(QWidget *parent, const QByteArray & byteArray, IConfig *config);

    ~ProgressDialog();


public slots:
    void show();

    /**
     * @brief finish scan process
     */
    void onComplete();

    /**
     * @brief change state of progress bar
     * @param progressValue - count task complete now
     */
    void onProgress(float progressValue);

    /**
     * @brief print value to frame log
     * @param fileName - name's file scanned
     * @param value - string to print
     */
    void onFoundGUID(QString fileName, QString guid);

    /**
     * @param fileName - name's file scanned
     */
    void onNotFoundGUID(QString fileName);

    /**
     * @brief print errors to frame log
     * @param fileName - name's file scanned
     * @param errMessage - description error
     */
    void onError(QString fileName, QString errMessage);

    /**
     * @brief print about interrupted scan process to frame log
     */
    void onInterrupted();

private slots:
    void done(int r);

    void on_cancel_clicked();

private:
    Ui::sign_scan_state *ui;

    const SearchType m_searchType;
    const QString m_searchPath;
    SearchController * m_searchController;

    QByteArray m_byteArray;

    Statistics m_Statistics;

    /**
     * @param printText - text to frame log
     * @param textColor - color of text
     */
    void printLog(QString printText, QColor textColor = Qt::black);

    bool confirmCancelScan();

    IConfig *m_config;

};

#endif // SIGN_SCAN_STATE_H
